package org.budo.support.javax.jms.util;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.jms.JMSException;
import javax.jms.MapMessage;

/**
 * @author limingwei
 */
public class MapMessageUtil {
    public static Map<String, Object> toMap(MapMessage mapMessage) {
        try {
            Map<String, Object> mapMsg = new HashMap<String, Object>();
            Enumeration<?> mapKeys = mapMessage.getMapNames();
            while (mapKeys != null && mapKeys.hasMoreElements()) {
                String key = (String) mapKeys.nextElement();
                Object value = mapMessage.getObject(key);
                mapMsg.put(key, value);
            }
            return mapMsg;
        } catch (JMSException e) {
            throw new RuntimeException(e);
        }
    }
}